using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ElteIk.RoboSoccer.Core;
using ElteIk.RoboSoccer.Core.Physics;
using ElteIk.RoboSoccer.Graphics;
using ElteIk.RoboSoccer.Simulator;
using ElteIk.RoboSoccer.TesterTactics;


namespace ElteIk.RoboSoccer.SimulatorTester
{
    public partial class SimulatorTesterForm : Form
    {
        private RoboSoccerGame game;
        private GdiGraphicsEngine engine;
        private RoboSoccerSimulator simulator;
        
        
        public SimulatorTesterForm()
        {
            InitializeComponent();

            simulator = new RoboSoccerSimulator(new TesterTactics.AdvencedRandomTactics(1), new TesterTactics.AdvencedRandomTactics(2));
            game = simulator.Game;
            engine = new Graphics.GdiGraphicsEngine(game, renderPanel);
            simulator.SimulationFinished += new EventHandler(OnSimulationFinished);
        }


        private void OnSimulationFinished(object sender, EventArgs e)
        {
            // now we can ask the simulator for the final result
            System.Windows.Forms.MessageBox.Show(simulator.GetTeamObjectives().GetTeamResultText());
        }

        private void SimulatorTesterForm_Load(object sender, EventArgs e)
        {
            // setup the starting state
            StartingState st = GetStartingStateExample3();
            // setup the objectives for our team
            TeamObjectives to = GetTeamObjectivesExample1();
            // start the simulation in normal mode
            simulator.Start(st, to, 4m);
            // start the simulation in quick mode - without displaying
            //simulator.QuickStart(st, to, 30m);
        }

        #region StartingState examples

        // scoring a goal at the beginning
        private StartingState GetStartingStateExample1()
        {
            StartingState st = new StartingState();
            st.SetBallState(new Vector2D(130, 30), 0, 300, 20);
            st.LeftTeamState.SetPlayerState(1, new Vector2D(100, 20), 0, 180, 270);
            return st;
        }

        // players in a line
        private StartingState GetStartingStateExample2()
        {
            StartingState st = new StartingState();
            st.LeftTeamState.SetPlayerState(0, new Vector2D(30,100), 0, 270);
            st.LeftTeamState.SetPlayerState(1, new Vector2D(50, 100), 0, 270);
            st.LeftTeamState.SetPlayerState(2, new Vector2D(70, 100), 0, 270);
            st.RightTeamState.SetPlayerState(0, new Vector2D(100, 100), 0, 270);
            st.RightTeamState.SetPlayerState(1, new Vector2D(120, 100), 0, 270);
            st.RightTeamState.SetPlayerState(2, new Vector2D(140, 100), 0, 270);
            return st;
        }

        // starts the ball with random moving
        private StartingState GetStartingStateExample3()
        {
            StartingState st = new StartingState();
            st.SetBallState(new Vector2D(80,40), 15, 45, 135, 3, 15);
            return st;
        }

        #endregion

        #region TeamObjectives examples

        private TeamObjectives GetTeamObjectivesExample1()
        {
            TeamObjectives to = new TeamObjectives(simulator.Game, simulator.Game.LeftTeam);
            to.AddObjective(new ScoringGoalObjective(simulator.Game, simulator.Game.LeftTeam, 10));
            to.AddObjective(new CleenSheetObjective(simulator.Game, simulator.Game.LeftTeam, 5));
            to.AddObjective(new BallTargetPositionObjective(game.Ball, new Vector2D(130, 30), 10, 3));
            return to;
        }

        #endregion
    }
}